package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.vo.CategoryTreeVo;
import com.atguigu.gmall.feign.product.CategoryFeignClient;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Api(tags = "远程调用-首页跳转")//web-all===>service-product
@Controller
public class IndexController {

    @Autowired
    CategoryFeignClient categoryFeignClient;

    @ResponseBody//压测
    @GetMapping("/hello")
    public String hello(){
        return "hello";
    }

    @RequestMapping({"/","/index.html"})
    public String index(Model model){
        //todo 远程调用 service-product 获取系统所有的三级分类数据
        Result<List<CategoryTreeVo>> categoryTrees = categoryFeignClient.getCategoryTree();//远程调用 返回json数据，转化为Result类型
        List<CategoryTreeVo> data = categoryTrees.getData();
        model.addAttribute("list", data);//带着的数据
        return "index/index";//跳转到首页
    }
}
